import axios from 'axios'
const service = axios.create({
     baseURL:'https://user.api.it120.cc/', // url = base url + request url
    // withCredentials: true, // send cookies when cross-domain requests
    timeout: 5000 // request timeout
})
// 响应拦截
service.interceptors.response.use(response => {
    return response.data
})

// 请求拦截
service.interceptors.request.use(request => {
    let userInfo = localStorage.getItem("userInfo")?JSON.parse(localStorage.getItem("userInfo")):{}
    let token = userInfo.token //登录标识
    if(token){
        request.headers['X-Token']=token
    }
    return request
})
export default service